﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Xioa_UI_Demo.Model;
using Xioa_UI.Controls;
using Xioa_UI.DataOrigin;
using Xioa_UI.Message;
using Xioa_UI.Service;
using System.Windows.Media;

namespace Xioa_UI_Demo
{
    public partial class CheckBoxGroupViewModel : ObservableObject
    {
        public ICommand XioaTestCommand { get; set; }
        public ICommand XioaTestStringCommand { get; set; }

        [ObservableProperty] private ObservableCollection<Cards>? _Cards;
        [ObservableProperty] private XioaCheckGroupList _Data;
        [ObservableProperty] private ObservableCollection<string> _Items;
        [ObservableProperty] public DateTime _Time = DateTime.Now;
        [ObservableProperty] private string? _ComboBoxSeletion;
        [ObservableProperty] private int _StepBarIndex = 0;

        [ObservableProperty]
        private ObservableCollection<XioaCarouselModel> _Carousellist = new ObservableCollection<XioaCarouselModel>();

        [ObservableProperty] private string? _searchText = "text";

        public CheckBoxGroupViewModel()
        {
            
            DispatcherHelper.Initialize();
            //Task.Run(() =>
            //{
            //    while (true)
            //    {
            //        DispatcherHelper.CheckBeginInvokeOnUI(() => { Console.WriteLine(SearchText); });
            //        Thread.Sleep(500);
            //    }
            //});

            XioaTestCommand = new XioaRelayAsyncCommand(() =>
            {
                XioaMessageBox.Show("");
                return Task.CompletedTask;
            });

            XioaTestStringCommand = new RelayCommand<string>(name => { XioaMessageBox.Show(name!); });


            Items = new ObservableCollection<string>
            {
                "Data01",
                "Data02",
                "Data03",
                "Data04",
                "Data05",
            };
            Carousellist.Add(new XioaCarouselModel()
            {
                Imgpath = "/assets/Carousel/Carousel01.jpg",
                Name = "XioaUI",
                Info = "XioaMessager",
                Command = new RelayCommand<string>(ShowCarouselContent)
            });
            Carousellist.Add(new XioaCarouselModel()
            {
                Imgpath = "/assets/Carousel/Carousel02.jpg",
                Name = "XioaUI",
                Info = "XioaMessager",
                Command = new RelayCommand<string>(ShowCarouselContent)
            });
            Carousellist.Add(new XioaCarouselModel()
            {
                Imgpath = "./assets/Carousel/Carousel03.jpg",
                Name = "XioaUI",
                Info = "XioaMessager",
                Command = new RelayCommand<string>(ShowCarouselContent)
            });
            Carousellist.Add(new XioaCarouselModel()
            {
                Imgpath = "/assets/Carousel/Carousel04.jpg",
                Name = "XioaUI",
                Info = "XioaMessager",
                Command = new RelayCommand<string>(ShowCarouselContent)
            });
            Carousellist.Add(new XioaCarouselModel()
            {
                Imgpath = "/assets/Carousel/Carousel05.jpg",
                Name = "Xioa",
                Info = "Xioa",
                Command = new RelayCommand<string>(ShowCarouselContent)
            });

            NavList = new ObservableCollection<NavButtonItem>()
            {
                new NavButtonItem
                {
                    Content = "Navigation",
                    Command = LookDataCommand,
                    ItemIcon = new BitmapImage(new Uri("/assets/api.png", UriKind.Relative))
                },
                new NavButtonItem
                {
                    Content = "Navigation",
                    Command = LookData1Command,
                    ItemIcon = new BitmapImage(new Uri("/assets/alipay.png", UriKind.Relative))
                },
                new NavButtonItem
                {
                    Content = "Navigation",
                    Command = LookData1Command,
                    ItemIcon = new BitmapImage(new Uri("/assets/android.png", UriKind.Relative))
                },
                new NavButtonItem
                {
                    Content = "Navigation",
                    Command = LookData1Command,
                    ItemIcon = new BitmapImage(new Uri("/assets/apple.png", UriKind.Relative))
                }
            };
            Data = new XioaCheckGroupList
            {
                Data = new List<XioaCheckGroupDataOrigin>()
                {
                    new XioaCheckGroupDataOrigin() { Content = "item1~item2~item3~item4", IsCheck = true },
                    new XioaCheckGroupDataOrigin() { Content = "item", IsCheck = true },
                    new XioaCheckGroupDataOrigin() { Content = "item", IsCheck = true },
                    new XioaCheckGroupDataOrigin() { Content = "item", IsCheck = true }
                }
            };

            Cards = new ObservableCollection<Cards>();
            Cards.Add(new Cards()
            {
                Header = "Brand Color(Click Me)",
                Content = "~text",
                HeaderBrush = new SolidColorBrush(Color.FromRgb(64, 158, 255))
            });
            Cards.Add(new Cards()
            {
                Header = "Success",
                Content = "~text",
                HeaderBrush = new SolidColorBrush(Color.FromRgb(103, 194, 58))
            });
            Cards.Add(new Cards()
            {
                Header = "Warning",
                Content = "~text",
                HeaderBrush = new SolidColorBrush(Color.FromRgb(230, 162, 60))
            });
            Cards.Add(new Cards()
            {
                Header = "Danger",
                Content = "~text",
                HeaderBrush = new SolidColorBrush(Color.FromRgb(245, 108, 108))
            });
            Cards.Add(new Cards()
            {
                Header = "Info",
                Content = "~text",
                HeaderBrush = new SolidColorBrush(Color.FromRgb(144, 147, 153))
            });


        }

        [RelayCommand]
        private void StepBarUp()
        {
            if (StepBarIndex < Items.Count - 1)
            {
                StepBarIndex++;
            }
        }

        [RelayCommand]
        private void StepDown()
        {
            if (StepBarIndex > 0)
            {
                StepBarIndex--;
            }
        }

        [RelayCommand]
        private void LookData()
        {
            Console.WriteLine(Time);
        }

        [RelayCommand]
        private void LookData1()
        {
            Console.WriteLine(Data);
        }

        [RelayCommand]
        private void ComboBoxChanged(XioaComboBox xioaComboBox)
        {
            ComboBoxSeletion = xioaComboBox.SelectedItem as string;
        }

        [RelayCommand]
        private void ShowCarouselContent(string? name)
        {
            XioaMessageBox.Show(name);
        }

        [RelayCommand]
        private void GetTime(object? time)
        {
            if (time == null)
            {
                XioaMessageBox.Show("请先选择时间");
                return;
            }

            var temp = (DateTime)time;
            XioaMessageBox.Show(temp.ToString(), "");
            Console.WriteLine(temp);
        }

        [ObservableProperty] private ObservableCollection<NavButtonItem> _NavList;


        [RelayCommand]
        private void InitializeTcpBorder(XioaTcpBorder tcpBorder)
        {
            var resx = tcpBorder.Initialize("xioa");
        }
    }
}